package com.ysxsoft.wdg.adapter.home;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ysxsoft.wdg.R;
import com.ysxsoft.wdg.bean.response.HomeProductResponse;
import com.ysxsoft.wdg.util.BigDecimalUtil;
import com.ysxsoft.wdg.util.ViewUtils;

/**
 * 精选商品
 */
public class JxGoodsAdapter extends BaseQuickAdapter<HomeProductResponse.DataBean, BaseViewHolder> {
    public JxGoodsAdapter(int layoutResId) {
        super(layoutResId);
    }

    public void clear() {
        getData().clear();
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeProductResponse.DataBean item) {
        TextView tvOldPrice2 = helper.getView(R.id.tv_old_money2);//隐藏到手价上边的旧价格
        tvOldPrice2.setVisibility(View.GONE);

        String oldP = item.getZk_final_price();
        String discount = item.getDiscount();
        helper.setText(R.id.tv_name, item.getTitle());
        TextView tvOldPrice = helper.getView(R.id.tv_old_money);
        ViewUtils.setDeletLine(tvOldPrice);
        tvOldPrice.setText(mContext.getString(R.string.price_rmb,oldP));//旧价格
        String sub = BigDecimalUtil.formatDoubleScale(BigDecimalUtil.sub(Double.parseDouble(oldP), Double.parseDouble(discount)));
        helper.setText(R.id.tv_money,mContext.getString(R.string.price_rmb,sub));//到手价格
        helper.setText(R.id.tv_quan, mContext.getString(R.string.price_rmb,discount) + "元优惠");//优惠券
        helper.setText(R.id.tv_sold, "赚" + mContext.getString(R.string.price_rmb,item.getZhuan()+""));//赚的钱数
        Glide.with(mContext).load(item.getPict_url()).into((ImageView) helper.getView(R.id.iv_pic));
    }
}
